package com.password.desktop.UI;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class ImageJLable extends JLabel {

	private final ImageIcon icon;

	public ImageJLable(ImageIcon icon) {
		this.icon = icon;
	}

	public ImageJLable(URL icon) {
		this.icon = new ImageIcon(icon);
	}

	private static final long serialVersionUID = 1L;

	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2=(Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); //消除锯齿状
		g.setPaintMode();
		g.drawImage(icon.getImage(), 0, 0, getWidth(), getHeight(), icon.getImageObserver());
	    super.paintComponent(g);
	}

}
